/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : WinPicInfoBar.c /Project:AVOS		       **
**        Revision : 1.0                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "WinPicInfoBarEvent.h"
#include "NetmenuSetupEvent.h"
extern INT32S WinPicInfoBarOnShow(PHWND hwnd, INT32S lpParam);
extern INT32S MiniBarOnShow(PHWND hwnd, INT32S lpParam);
void SetWinPicInfoBarPalette(void)
{
    YUVENTRY mask_para[4] = {0,110,4095,4095};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 15208,0x8000 | 16216,0x8000 | 17880,0x8000 | 16392,16280,16184,16088,16040,16024,15880,15208,15720,15016,15064,15304,15144};
    AWSetPalette(0,16, palette_para);
    return ;
}
INT32S WinPicInfoBarMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
	   switch( msg_type){
	   	case WM_CREATE:
	   		//SetWinPicInfoBarPalette();
	   		break;
        case WM_SHOWWINDOW:
            return WinPicInfoBarOnShow(hwnd, lpParam) ;
       default:
            return 0 ;
         }
    return 0 ;
  }
void SetWinPicInfoBarPos(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize){
	case OsdSize576iCVBS:
	case OsdSize576i:
	case OsdSize576p:
            RECT StandardWindowRect = {0,0,720,576};
            pControl->winrect = StandardWindowRect;
            CREATEWINDOWPARAM StandardWindowPara = {2,{{104,488,512,32},
            {540,60,120,32},
            {0,0,0,0},
            {0,0,0,0}},
            {PF_PALETTE_256,PF_PALETTE_256,0,0},SetWinPicInfoBarPalette};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&StandardWindowPara);
            break ;

#ifdef SUPPORT_VGA	
	case OsdSizeVga:
            RECT VgaWindowRect480 = {0,0,1028,768};
            pControl->winrect = VgaWindowRect480;
            CREATEWINDOWPARAM VgaWindowPara480 = {2,{{104,520,512,32},
            {540,60,120,32},
            {0,0,0,0},
            {0,0,0,0}},
            {PF_PALETTE_256,PF_PALETTE_256,0,0},SetWinPicInfoBarPalette};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&VgaWindowPara480);
            break ;
#endif
			
	case OsdSize480iCVBS: 
	case OsdSize480i:
	case OsdSize480p:   	
	default:
            RECT StandardWindowRect480 = {0,0,720,576};
            pControl->winrect = StandardWindowRect480;
            CREATEWINDOWPARAM StandardWindowPara480 = {2,{{104,418,512,32},
            {540,60,120,32},
            {0,0,0,0},
            {0,0,0,0}},
            {PF_PALETTE_256,PF_PALETTE_256,0,0},SetWinPicInfoBarPalette};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&StandardWindowPara480);
            break ;
    }//end of switch
    return;
}

HWND *CreateControlWinPicInfoBar(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
    switch(CurOsdSize){
	case OsdSize576iCVBS:
	case OsdSize576i:
	case OsdSize576p:
        	   CREATEWINDOWPARAM window_para = {2,{{104,488,512,32},
            {540,60,120,32},
            {0,0,0,0},
            {0,0,0,0}},
           {PF_PALETTE_256,PF_PALETTE_256,0,0},SetWinPicInfoBarPalette};
    //Create Menu Window -- 0
       		 pNewControl = AWCreateWinControl("TWindow","WinPicInfoBar",WS_OVERLAPPEDWINDOW,
		         0,0,0,0,NULL, (INT32S)&window_para,WinPicInfoBarMsgProc) ;
          	pNewControl->win_id = 0 ;
            break ;

#ifdef SUPPORT_VGA	
	case OsdSizeVga:
        	CREATEWINDOWPARAM window_paraVga= {2,{{104,520,512,32},
            {540,60-WinStart_y,120,32},
            {0,0,0,0},
            {0,0,0,0}},
        {PF_PALETTE_256,PF_PALETTE_256,0,0},SetWinPicInfoBarPalette};
    //Create Menu Window -- 0
    pNewControl = AWCreateWinControl("TWindow","WinPicInfoBar",WS_OVERLAPPEDWINDOW,
		         0,0,0,0,NULL, (INT32S)&window_paraVga,WinPicInfoBarMsgProc) ;
    pNewControl->win_id = 0 ;
            break ;
#endif
			
	case OsdSize480iCVBS: 
	case OsdSize480i:
	case OsdSize480p: 
	default:
        	CREATEWINDOWPARAM window_para480= {2,{{104,418,512,32},
            {540,60,120,32},
            {0,0,0,0},
            {0,0,0,0}},
        {PF_PALETTE_256,PF_PALETTE_256,0,0},SetWinPicInfoBarPalette};
    //Create Menu Window -- 0
    pNewControl = AWCreateWinControl("TWindow","WinPicInfoBar",WS_OVERLAPPEDWINDOW,
		         0,0,0,0,NULL, (INT32S)&window_para480,WinPicInfoBarMsgProc) ;
    pNewControl->win_id = 0 ;
            break ;
    }//end of switch
            return pNewControl;
}

void SetPicInfoBarPos(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
	case OsdSize576iCVBS:
	case OsdSize576i:
	case OsdSize576p:
            pControl->winrect.top = pControl->parent->winrect.top + 488;
            pControl->winrect.left = pControl->parent->winrect.left + 104;
            pControl->winrect.width = 512;
            pControl->winrect.height = 32;
            pControl->draw_info_num = 9;
            RECT StandardDrawRect[9] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,512,32},
            {pControl->winrect.left + 56,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 106,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 156,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 206,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 256,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 306,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 338,pControl->winrect.top + 0,170,32},
            {pControl->winrect.left + 350,pControl->winrect.top + 5,160,27}
             };
            for(iLoop=0; iLoop < 9; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &StandardDrawRect[iLoop], sizeof(RECT));
            break ;

#ifdef SUPPORT_VGA	
	case OsdSizeVga:
            pControl->winrect.top = pControl->parent->winrect.top + 520;
            pControl->winrect.left = pControl->parent->winrect.left + 104;
            pControl->winrect.width = 512;
            pControl->winrect.height = 32;
            pControl->draw_info_num = 9;
            RECT VgaDrawRect480[9] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,512,32},
            {pControl->winrect.left + 56,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 106,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 156,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 206,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 256,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 306,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 338,pControl->winrect.top + 0,170,32},
            {pControl->winrect.left + 350,pControl->winrect.top + 5,160,27}
             };
            for(iLoop=0; iLoop < 9; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &VgaDrawRect480[iLoop], sizeof(RECT));
            break ;
#endif
			
	case OsdSize480iCVBS: 
	case OsdSize480i:
	case OsdSize480p: 
	default:
            pControl->winrect.top = pControl->parent->winrect.top + 418;
            pControl->winrect.left = pControl->parent->winrect.left + 104;
            pControl->winrect.width = 512;
            pControl->winrect.height = 32;
            pControl->draw_info_num = 9;
            RECT StandardDrawRect480[9] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,512,32},
            {pControl->winrect.left + 56,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 106,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 156,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 206,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 256,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 306,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 338,pControl->winrect.top + 0,170,32},
            {pControl->winrect.left + 350,pControl->winrect.top + 5,160,27}
             };
            for(iLoop=0; iLoop < 9; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &StandardDrawRect480[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}

	
INT32S PicInfoBarMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
    	
        case WM_SHOWWINDOW:
            return PicInfoBarOnShow(hwnd, lpParam) ;
        case WM_KEYDOWN:
            return PicInfoBarOnKeyPress(hwnd, lpParam) ;
        default:
            return PicInfoBarOnOtherEvent(hwnd, msg_type, lpParam) ;
    }
    return 0 ;
}
INT32S MiniBarMsgProc(PHWND hwnd,INT32U msg_type,INT32S lpParam)
{
    switch( msg_type){
    	
        case WM_KEYDOWN:
            return MiniBarOnKeyPress(hwnd, lpParam) ;
        default:
            return 0;
    }
    return 0 ;
}
HWND *CreateControlPicInfoBar(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- PicInfoBar
    HWND *pNewControl;
    switch(CurOsdSize){
	case OsdSize576iCVBS:
	case OsdSize576i:
	case OsdSize576p:
        	  pNewControl = AWCreateWinControl("TControl","PicInfoBar",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		         104,488,512,32,pParent,0,PicInfoBarMsgProc) ;
    pNewControl->win_id = 2 ;
    pNewControl->draw_info_num = 9;
    pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
    DRAWINFO DrawDatas[9] = {
        {0,0,0,0,(INT32U)ICON_INFOBAR_STATUS512,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PREV_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PLAY_FOCUS,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_NEXT_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_ROTATE_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_STOP_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_ZOOM_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_INFOBAR_STATUS140,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_STRING_DATA}
        };
    memcpy(pNewControl->draw_info, DrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;

#ifdef SUPPORT_VGA	
	case OsdSizeVga:
    pNewControl = AWCreateWinControl("TControl","PicInfoBar",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		         104,520,512,32,pParent,0,PicInfoBarMsgProc) ;
    pNewControl->win_id = 2 ;
    pNewControl->draw_info_num = 9;
    pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
    DRAWINFO DrawDatasVga[9] = {
        {0,0,0,0,(INT32U)ICON_INFOBAR_STATUS512,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PREV_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PLAY_FOCUS,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_NEXT_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_ROTATE_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_STOP_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_ZOOM_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_INFOBAR_STATUS140,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_STRING_DATA}
        };
    memcpy(pNewControl->draw_info, DrawDatasVga, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
#endif
			
	case OsdSize480iCVBS: 
	case OsdSize480i:
	case OsdSize480p:
	default:
    pNewControl = AWCreateWinControl("TControl","PicInfoBar",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		         104,418,512,32,pParent,0,PicInfoBarMsgProc) ;
    pNewControl->win_id = 2 ;
    pNewControl->draw_info_num = 9;
    pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
    DRAWINFO DrawDatas480[9] = {
        {0,0,0,0,(INT32U)ICON_INFOBAR_STATUS512,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PREV_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_PLAY_FOCUS,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_NEXT_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_ROTATE_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_STOP_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_ZOOM_LOSE,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)ICON_INFOBAR_STATUS140,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_STRING_DATA}
        };
    memcpy(pNewControl->draw_info, DrawDatas480, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
    }//end of switch
            return pNewControl;
}

void SetMiniBarPos(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
		
#ifdef SUPPORT_VGA	
	case OsdSizeVga:
            pControl->winrect.top = pControl->parent->winrect.top + 60-WinStart_y;
            pControl->winrect.left = pControl->parent->winrect.left + 540;
            pControl->winrect.width = 120;
            pControl->winrect.height = 32;
            pControl->draw_info_num = 4;
            RECT VgaDrawRect[4] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,120,32},
            {pControl->winrect.left + 4,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 36,pControl->winrect.top + 0,16,32},
            {pControl->winrect.left + 54,pControl->winrect.top + 0,32,32},
            };
            for(iLoop=0; iLoop < 4; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &VgaDrawRect[iLoop], sizeof(RECT));
            break ;
#endif

        default:
            pControl->winrect.top = pControl->parent->winrect.top + 60;
            pControl->winrect.left = pControl->parent->winrect.left + 540;
            pControl->winrect.width = 120;
            pControl->winrect.height = 32;
            pControl->draw_info_num = 4;
            RECT StandardDrawRect[4] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,120,32},
            {pControl->winrect.left + 4,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 36,pControl->winrect.top + 0,16,32},
            {pControl->winrect.left + 54,pControl->winrect.top + 0,32,32},
            };
            for(iLoop=0; iLoop < 4; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &StandardDrawRect[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}

HWND *CreateControlMiniBar(HWND *pParent)
{
    //Create Control -- WinPicFileInfo
    HWND *pNewControl;
    switch(CurrentOsdSize){
#ifdef SUPPORT_VGA	
	case OsdSizeVga:
        	   pNewControl = AWCreateWinControl("TControl","MiniBar",(WS_CHILDWINDOW | 	WS_CHILDWINDOW),
		         540,60-WinStart_y,120,32,pParent,0,MiniBarMsgProc) ;
    pNewControl->win_id = 4 ;
    pNewControl->draw_info_num = 4;
    pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
    DRAWINFO DrawDatasVga[4] = {
       // {0,0,0,0,(INT32U)ICON_INFOBAR_STATUS1,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA}};
    memcpy(pNewControl->draw_info, DrawDatasVga, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
#endif

        default:
        	   pNewControl = AWCreateWinControl("TControl","MiniBar",(WS_CHILDWINDOW | 	WS_CHILDWINDOW),
		         540,60,120,32,pParent,0,MiniBarMsgProc) ;
    pNewControl->win_id = 4 ;
    pNewControl->draw_info_num = 4;
    pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
    DRAWINFO DrawDatas[4] = {
       // {0,0,0,0,(INT32U)ICON_INFOBAR_STATUS1,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
        {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA}};
    memcpy(pNewControl->draw_info, DrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
    }//end of switch
            return pNewControl;
}

HWND* CreateMenuWinPicInfoBar(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pWinPicInfoBar = CreateControlWinPicInfoBar(NULL,CurrentOsdSize);
    SetWinPicInfoBarPos(pWinPicInfoBar,CurrentOsdSize);

    pNewControl= CreateControlPicInfoBar(pWinPicInfoBar,CurrentOsdSize);
    SetPicInfoBarPos(pNewControl,CurrentOsdSize);

    pNewControl= CreateControlMiniBar(pWinPicInfoBar);
    SetMiniBarPos(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pWinPicInfoBar;
    pWin->pFocusControl = AWFindWinCtrlByName("PicInfoBar");
    return pWinPicInfoBar;
}

void WinResetWinPicInfoBarControlsPos(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://WinPicInfoBar
            SetWinPicInfoBarPos(pControl,CurOsdSize) ;
            break ;
        case 2://PicInfoBar
            SetPicInfoBarPos(pControl,CurOsdSize) ;
            break ;
        case 4://MiniBar
            SetMiniBarPos(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetWinPicInfoBarPos(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("WinPicInfoBar");
    if(pControl == NULL) return ;

    WinResetWinPicInfoBarControlsPos(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetWinPicInfoBarPos(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}

